package com.shushan.login.bean;

import android.util.Log;

import com.android.net.bean.NetBaseBean;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: UserBean
 * @Desciption: 用户信息bean
 * @author: yichaohua
 * @date: 2018-04-14
 */
@DatabaseTable(tableName = "user_table")
public class UserBean extends NetBaseBean {

    private static final String TAG = "UserBean";

    @DatabaseField(id = true)
    public int id;
    @DatabaseField
    public String password;
    @DatabaseField
    public String nickname;
    @DatabaseField
    public String phone;
    @DatabaseField
    public String sex;
    @DatabaseField
    public String avatar;
    @DatabaseField
    public int bind_wx;//0：未绑定微信 1：绑定微信
    @DatabaseField
    public int vip;//0:不是vip 1：vip
    @DatabaseField
    public int share_vip; //0表示没有免费使用时间 1表示还有免费使用时间
    @DatabaseField
    public String vip_endtime;//vip到期时间
    @DatabaseField
    public int svip;//0:不是svip 1：svip
    @DatabaseField
    public int extractvip = 0;
    @DatabaseField
    public int tb_vip = 0;
    @DatabaseField
    public int sz_vip = 0;
    @DatabaseField
    public int ks_vip = 0;
    @DatabaseField
    public int ky_vip = 0;
    @DatabaseField
    public int dc_vip = 0;
    @DatabaseField
    public int tl_vip = 0;
    @DatabaseField
    public int share_vip_last_time;//免费vip剩余时间：单位天
    @DatabaseField
    public String activity_name;//剩余一天时弹出对话框的使用字段
    @DatabaseField
    public int first_time;//是否是第一次登陆 1：是 0：否
    @DatabaseField
    public String invite_code;//个人邀请码

    private List<ChildBean> childList = new ArrayList<ChildBean>();

    @Override
    public void initByJson(JSONObject jsonObject) throws JSONException {
        Log.i(TAG,"jsonObject=" + jsonObject.toString());

        JSONObject userJson = jsonObject.optJSONObject("user");

        id = userJson.optInt("id",-1);
        password = userJson.optString("password","");

        nickname = userJson.optString("nickname","");
        phone = userJson.optString("phone","");
        sex = userJson.optString("sex","");
        avatar = userJson.optString("avatar","");
        bind_wx = userJson.optInt("bind_wx",0);
        vip = userJson.optInt("vip",0);
        share_vip = userJson.optInt("share_vip",0);
        vip_endtime = userJson.optString("vip_endtime","");
        svip = userJson.optInt("svip",0);
        extractvip = userJson.optInt("extractvip",0);
        share_vip_last_time = userJson.optInt("share_vip_last_time",0);
        activity_name = userJson.optString("activity_name","");
        first_time = userJson.optInt("first_time",0);
        invite_code = userJson.optString("invite_code","");

        JSONObject classvipJson = userJson.optJSONObject("classificationvip");
        if(classvipJson != null){
            tb_vip = classvipJson.optInt("tb_vip",0);
            sz_vip = classvipJson.optInt("sz_vip",0);
            ks_vip = classvipJson.optInt("ks_vip",0);
            ky_vip = classvipJson.optInt("ky_vip",0);
            dc_vip = classvipJson.optInt("dc_vip",0);
            tl_vip = classvipJson.optInt("tl_vip",0);
        }

        JSONArray jsonArray = userJson.optJSONArray("child");
        if(jsonArray != null) {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject json = jsonArray.optJSONObject(i);

                ChildBean childBean = new ChildBean();
                childBean.initByJson(json);
                childList.add(childBean);
            }
        }
    }

    public List<ChildBean> getChildList() {
        return childList;
    }

    public void setChildList(List<ChildBean> childList) {
        this.childList = childList;
    }
}
